package com.rzjm.api.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 说明：日期处理
 * 创建人：zw
 * 修改时间：2015年11月24日
 * @version
 */
public class DateUtil {

	private final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
	private final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
	private final static SimpleDateFormat sdfDayMonth = new SimpleDateFormat("yyyy-MM");
	public final static SimpleDateFormat sdfMonthSimple = new SimpleDateFormat("yyyyMM");
	private final static SimpleDateFormat sdfDayCN = new SimpleDateFormat("yyyy年MM月dd日");
	private final static SimpleDateFormat sdfDay1 = new SimpleDateFormat("yy/MM/dd");
	private final static SimpleDateFormat sdfDay2 = new SimpleDateFormat("yy-MM-dd");
	private final static SimpleDateFormat sdfDays = new SimpleDateFormat("yyyyMMdd");
	private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private final static SimpleDateFormat sdfSimpleTime = new SimpleDateFormat("HH:mm:ss");
	private final static SimpleDateFormat sdfSimpleTime1 = new SimpleDateFormat("HH:mm");
	private final static SimpleDateFormat sdfTime1 = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
	private final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss");
	private final static SimpleDateFormat sdfffTimes = new SimpleDateFormat("yyyyMMddHHmmss");

	/**
	 * 获取yyyyMMddHHmmss格式
	 * @return
	 */
	public static String getSdfTimes() {
		return sdfTimes.format(new Date());
	}

	/**
	 * 获取yyyy年MM月dd日格式
	 * @return
	 */
	public static String getSdfTimesCN() {
		return sdfDayCN.format(new Date());
	}


	/**
	 * 获取yyyyMMddHHmmss格式
	 * @return
	 */
	public static String getDayStr(Date date) {
		return sdfDay.format(date);
	}

	/**
	 * 获取yyyyMMddHHmmss格式
	 * @return
	 */
	public static String getMonthStr(Date date) {
		return sdfDayMonth.format(date);
	}


	/**
	 * 获取yyyyMMddHHmmss格式
	 * @return
	 */
	public static String getMonthSimpleStr(Date date) {
		return sdfMonthSimple.format(date);
	}


	/**
	 * 格式化日期
	 * @return
	 */
	public static Date formatDate(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}


	/**
	 * 格式化日期
	 * @return
	 */
	public static Date formatDateTime(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}


	/**
	 * 获取YYYY格式
	 * @return
	 */
	public static String getSdfffTimes() {
		return sdfffTimes.format(new Date());
	}


	/**
	 *  获取多少秒之后的时间
	 * @return
	 */
	public static Date getAfterSecondsByOld(Date date,int seconds){
		Calendar calendar = Calendar.getInstance(); // java.util包
		calendar.setTime(date);
		calendar.add(Calendar.SECOND,seconds);
		return calendar.getTime();
	}

	/**
	 * 获取时间的 年月日时分秒
	 * @param date
	 * @param timeCode  Y-年 M-月份 D- 日期  H- 小时 m:分钟 s - 秒数  wfy - 一周的第几天
	 * @return
	 */
	public static int getTimeByTimeCode(Date date,String timeCode){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int ret = -1;
		switch (timeCode){
			case "Y": return cal.get(Calendar.YEAR);
			case "M": return cal.get(Calendar.MONTH);
			case "D": return cal.get(Calendar.DAY_OF_MONTH);
			case "H": return cal.get(Calendar.HOUR_OF_DAY);
			case "m": return cal.get(Calendar.MINUTE);
			case "s": return cal.get(Calendar.SECOND);
			case "wfy": return cal.get(Calendar.DAY_OF_WEEK);
		}
//		int year = cal.get(Calendar.YEAR);//获取年份
//		int month=cal.get(Calendar.MONTH);//获取月份
//		int day=cal.get(Calendar.DATE);//获取日
//		int hour=cal.get(Calendar.HOUR);//小时
//		int minute=cal.get(Calendar.MINUTE);//分
//		int second=cal.get(Calendar.SECOND);//秒
//		int WeekOfYear = cal.get(Calendar.DAY_OF_WEEK);//一周的第几天
		return ret;
	}

	/**
	 * 获取YYYY格式
	 * @return
	 */
	public static String getYear() {
		return sdfYear.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD格式
	 * @return
	 */
	public static String getDay() {
		return sdfDay.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD格式
	 * @return
	 */
	public static String getDayByDate(Date date) {
		return sdfDay.format(date);
	}



	public static Date getTimeByTimspan(Long time){
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(time * 1000);
		return calendar.getTime();
	}


	/**
	 * 获取当前日期是星期几<br>
	 *
	 * @param date
	 * @return 当前日期是星期几
	 */
	public static String getWeekOfDate(Date date) {
		String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	/**
	 * 获取当前日期是星期几<br>
	 *
	 * @param date
	 * @return 当前日期是星期几
	 */
	public static int getWeekIndexOfDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return w;
	}

	/**
	 * 获取过去第几天的日期(- 操作) 或者 未来 第几天的日期( + 操作)
	 *
	 * @param past
	 * @return
	 */
	public static String getAfterDate(int past) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
		Date today = calendar.getTime();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String result = format.format(today);
		return result;
	}

	/**
	 * 添加分钟
	 *
	 * @param past
	 * @return
	 */
	public static Date getAfterDateMinute(int past) {
		Date currentDate = new Date();
		long fiveMinutesInMillis = past * 60 * 1000; // 5分钟的毫秒数
		long newTime = currentDate.getTime() + fiveMinutesInMillis;
		Date newDate = new Date();
		newDate.setTime(newTime);
		System.out.println("当前时间：" + currentDate);
		System.out.println("增加" + past + "分钟后的时间：" + newDate);
		return newDate;
	}

	/**
	 * 添加分钟
	 *
	 * @param past
	 * @return
	 */
	public static Date getAfterDateMinuteByDate(Date currentDate, int past) {
		long fiveMinutesInMillis = past * 60 * 1000; // 5分钟的毫秒数
		long newTime = currentDate.getTime() + fiveMinutesInMillis;
		Date newDate = new Date();
		newDate.setTime(newTime);
		System.out.println("当前时间：" + currentDate);
		System.out.println("增加" + past + "分钟后的时间：" + newDate);
		return newDate;
	}

	/**
	 * 获取过去第几天的日期(- 操作) 或者 未来 第几天的日期( + 操作)
	 *
	 * @param past
	 * @return
	 */
	public static String getAfterDate(Date date, int past) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
		Date today = calendar.getTime();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String result = format.format(today);
		return result;
	}

	/**
	 *  获取时间之后的几天的日期，周日要排除掉
	 * @param date
	 * @param days
	 * @return
	 */
	public static List<String> getAfterDateByDays(Date date, int days) {
		List<String> dayStr = new ArrayList<>();
		for (int i = 0; i < days; i++){
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			int weekday = calendar.get(Calendar.DAY_OF_WEEK);
			String day = "";
			if(weekday == 7){
				calendar.add(Calendar.DATE, 1);
				date = calendar.getTime();
				day = getAfterDate(calendar.getTime(), 1);
				calendar.add(Calendar.DATE, 1);
				date = calendar.getTime();
			}else{
				if(i == 0){
					calendar.add(Calendar.DATE, 0);
					day = getAfterDate(calendar.getTime(), 0);
				}else{
					calendar.add(Calendar.DATE, 1);
					date = calendar.getTime();
					day = getAfterDate(calendar.getTime(), 0);
				}
			}
			dayStr.add(day);


		}
		return dayStr;
	}

	/**
	 *  获取时间之后的几天的日期，并排除周几
	 * @param date
	 * @param days
	 * @return
	 */
	public static Map<String, Object> getAfterDateByDaysExWeek(Date date, int days, List<Integer> exWeek) {
		Map<String, Object> map = new HashMap<>();
		List<String> dayStr = new ArrayList<>();
		List<String> dayWeekStr = new ArrayList<>();
		if (exWeek != null && exWeek.size() > 6){// 全部去除
			return map;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		for (int i = 0; i < days; i++){
			int weekday = calendar.get(Calendar.DAY_OF_WEEK);
			String day = "";
			String dayWeek = "";
			if (exWeek != null && exWeek.size() > 0){
				if (exWeek.contains(Integer.valueOf(weekday))){
					int ex = 0; // 排除的时间天数，有可能排除的周几是连续的
					int calWeekday = weekday;
					for (int j = 0; j < exWeek.size(); j++) {
						if (calWeekday == exWeek.get(j).intValue()) {
							ex++;
							calWeekday++;
						}else if (ex > 0){
							break;
						}
					}
					calendar.add(Calendar.DATE, ex);
					day = getAfterDate(calendar.getTime(), 0);
					dayWeek = day + "(" + getWeekName(calWeekday) + ")";
					calendar.add(Calendar.DATE, 1);
				}else {
					calendar.add(Calendar.DATE, 0);
					day = getAfterDate(calendar.getTime(), 0);
					dayWeek = day + "(" + getWeekName(weekday) + ")";
					calendar.add(Calendar.DATE, 1);
				}
			}else {
				if(i == 0){
					calendar.add(Calendar.DATE, 0);
					day = getAfterDate(calendar.getTime(), 0);
					dayWeek = day + "(" +  getWeekName(weekday) + ")";
				}else{
					calendar.add(Calendar.DATE, 1);
					day = getAfterDate(calendar.getTime(), 0);
					dayWeek = day + "(" + getWeekName(weekday + 1) + ")";
				}
			}
			dayStr.add(day);
			dayWeekStr.add(dayWeek);
		}
		map.put("dayStr", dayStr);
		map.put("dayWeekStr", dayWeekStr);
		return map;
	}


	/**
	 * 获取YYYY-MM-DD格式
	 * @return
	 */
	public static String getDay1() {
		return sdfDay1.format(new Date());
	}
	/**
	 * 获取YY-MM-DD格式
	 * @return
	 */
	public static String getDay2() {
		return sdfDay2.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD格式
	 * @return
	 */
	public static String getDateByFormat(Date date,String format) {
		SimpleDateFormat sdfDays = new SimpleDateFormat(format);
		return sdfDays.format(date);
	}

	/**
	 * 获取YYYYMMDD格式
	 * @return
	 */
	public static String getDays(){
		return sdfDays.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * @return
	 */
	public static String getTime() {
		return sdfTime.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * @return
	 */
	public static String getTime(Date date) {
		return sdfTime.format(date);
	}
	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * @return
	 */
	public static String getSimpleTime(Date date) {
		return sdfSimpleTime.format(date);
	}

	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * @return
	 */
	public static String getSimpleTime1(Date date) {
		return sdfSimpleTime1.format(date);
	}




	/**
	 * 获取YY/MM/DD HH:mm:ss格式
	 * @return
	 */
	public static String getTime1() {
		return sdfTime1.format(new Date());
	}

	/**
	* @Title: compareDate
	* @Description: TODO(日期比较，如果s>=e 返回true 否则返回false)
	* @param s
	* @param e
	* @return boolean
	* @throws
	* @author fh
	 */
	public static boolean compareDate(String s, String e) {
		if(fomatDate(s)==null||fomatDate(e)==null){
			return false;
		}
		return fomatDate(s).getTime() >=fomatDate(e).getTime();
	}


	public static Date stampToDate(String date){
		SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy K:m:s a", Locale.ENGLISH);
		Date d2 = null;
		try {
			d2 = sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d2;
	}


	/**
	 * 格式化日期
	 * @return
	 */
	public static Date fomatDate(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 格式化日期
	 * @return
	 */
	public static String fomatDate(String dateStr,String format) {
		DateFormat fmt = new SimpleDateFormat(format);
		try {
			Date date = fmt.parse(dateStr);
			return sdfDay.format(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 格式化日期
	 * @return
	 */
	public static Date ConvertDateByformat(String date,String format) {
		DateFormat fmt = new SimpleDateFormat(format);
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 校验日期是否合法
	 * @return
	 */
	public static boolean isValidDate(String s) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			fmt.parse(s);
			return true;
		} catch (Exception e) {
			// 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
			return false;
		}
	}

	/**
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static int getDiffYear(String startTime,String endTime) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			//long aa=0;
			int years=(int) (((fmt.parse(endTime).getTime()-fmt.parse(startTime).getTime())/ (1000 * 60 * 60 * 24))/365);
			return years;
		} catch (Exception e) {
			// 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
			return 0;
		}
	}

	/**
     * <li>功能描述：时间相减得到天数
     * @param beginDateStr
     * @param endDateStr
     * @return
     * long
     * @author Administrator
     */
    public static long getDaySub(String beginDateStr,String endDateStr){
        long day=0;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate = null;
        Date endDate = null;

		try {
			beginDate = format.parse(beginDateStr);
			endDate= format.parse(endDateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
		//System.out.println("相隔的天数="+day);

        return day;
    }

    /**
     *
     *@author by  zhouwei
     *@createtime: 2017/9/22 11:45
     *@Description：判断当前时间是否在次时间段内
     *@modifytime:   begintime endtime  格式  06：00
     *
     */
	public static boolean isBelongInTime(String begintime,String endtime){
		SimpleDateFormat df = new SimpleDateFormat("HH:mm");//设置日期格式
		Date now = null;
		Date beginTime = null;
		Date endTime = null;
		try {
			now = df.parse(df.format(new Date()));
			beginTime = df.parse(begintime);
			endTime = df.parse(endtime);
		} catch (Exception e) {
			e.printStackTrace();
		}

		boolean flag = belongCalendar(now, beginTime, endTime);
		return flag;
	}

	/**
	 * 判断时间是否在时间段内
	 * @param nowTime
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	public static boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
		Calendar date = Calendar.getInstance();
		date.setTime(nowTime);

		Calendar begin = Calendar.getInstance();
		begin.setTime(beginTime);

		Calendar end = Calendar.getInstance();
		end.setTime(endTime);

		if (date.after(begin) && date.before(end)) {
			return true;
		} else {
			return false;
		}
	}

    /**
     * 得到n天之后的日期
     * @param days
     * @return
     */
    public static String getAfterDayDate(int days) {
//    	int daysInt = Integer.parseInt(days);

        Calendar calendar = Calendar.getInstance(); // java.util包
        calendar.add(Calendar.DATE, days); // 日期减 如果不够减会将月变动
        Date date = calendar.getTime();

        SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = sdfd.format(date);

        return dateStr;
    }


	/**
	 * 得到n天之后的日期
	 * @param days
	 * @return
	 */
	public static Date getBeginDayDate(Date date, int days) {
		Calendar calendar = Calendar.getInstance(); // java.util包
		calendar.setTime(date);
		if(days != 0){
			calendar.add(Calendar.DAY_OF_MONTH, days); // 日期减 如果不够减会将月变动
		}
		calendar.set(Calendar.HOUR_OF_DAY,0);
		calendar.set(Calendar.MINUTE,0);
		calendar.set(Calendar.SECOND,0);
		Date dateNow = calendar.getTime();
		return dateNow;
	}

	public static String getDateBeginTime(Date date, int days) {
		return getTime(getBeginDayDate(date,days));
	}


	/**
	 * 得到n天之后的日期
	 * @param days
	 * @return
	 */
	public static Date getAfterDayDate(Date date, int days) {
		Calendar calendar = Calendar.getInstance(); // java.util包
		calendar.setTime(date);
		if(days!= 0){
			calendar.add(Calendar.DAY_OF_MONTH, days); // 日期减 如果不够减会将月变动
		}
		calendar.set(Calendar.HOUR_OF_DAY,23);
		calendar.set(Calendar.MINUTE,59);
		calendar.set(Calendar.SECOND,59);
		Date dateNow = calendar.getTime();
		return dateNow;
	}


	public static String getDateEndTime(Date date, int days) {
		return getTime(getAfterDayDate(date,days));
	}

	/**
	 * 两个时间之间相差距离多少天
	 * @param str1 时间参数 1：
	 * @param str2 时间参数 2：
	 * @return 相差天数
	 */
	public static long getDistanceDays(String str1, String str2) throws Exception{
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date one;
		Date two;
		long days=0;
		try {
			one = df.parse(str1);
			two = df.parse(str2);
			long time1 = one.getTime();
			long time2 = two.getTime();
			long diff ;
			if(time1<time2) {
				diff = time2 - time1;
			} else {
				diff = time1 - time2;
			}
			days = diff / (1000 * 60 * 60 * 24);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return days;
	}

	/**
	 * 两个时间相差距离多少天多少小时多少分多少秒
	 * @param str1 时间参数 1 格式：1990-01-01 12:00:00
	 * @param str2 时间参数 2 格式：2009-01-01 12:00:00
	 * @return long[] 返回值为：{天, 时, 分, 秒}
	 */
	public static long[] getDistanceTimes(String str1, String str2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date one;
		Date two;
		long day = 0;
		long hour = 0;
		long min = 0;
		long sec = 0;
		try {
			one = df.parse(str1);
			two = df.parse(str2);
			long time1 = one.getTime();
			long time2 = two.getTime();
			long diff ;
			if(time1<time2) {
				diff = time2 - time1;
			} else {
				diff = time1 - time2;
			}
			day = diff / (24 * 60 * 60 * 1000);
			hour = (diff / (60 * 60 * 1000) - day * 24);
			min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
			sec = (diff/1000-day*24*60*60-hour*60*60-min*60);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long[] times = {day, hour, min, sec};
		return times;
	}


	/**
	 * 两个时间相差距离多少天多少小时多少分多少秒
	 * @param date1 时间参数 1 格式：1990-01-01 12:00:00
	 * @param date2 时间参数 2 格式：2009-01-01 12:00:00
	 * @return long[] 返回值为：{天, 时, 分, 秒}
	 */
	public static long[] getDistanceTimes(Date date1, Date date2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long day = 0;
		long hour = 0;
		long min = 0;
		long sec = 0;
		try {
			long time1 = date1.getTime();
			long time2 = date2.getTime();
			long diff ;
			if(time1<time2) {
				diff = time2 - time1;
			} else {
				diff = time1 - time2;
			}
			day = diff / (24 * 60 * 60 * 1000);
			hour = (diff / (60 * 60 * 1000) - day * 24);
			min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
			sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
		} catch (Exception e) {
			e.printStackTrace();
		}
		long[] times = {day, hour, min, sec};
		return times;
	}

	/**
	 * 两个时间相差距离多少天多少小时多少分多少秒
	 * @param str1 时间参数 1 格式：1990-01-01 12:00:00
	 * @param str2 时间参数 2 格式：2009-01-01 12:00:00
	 * @return String 返回值为：xx天xx小时xx分xx秒
	 */
	public static String getDistanceTime(String str1, String str2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date one;
		Date two;
		long day = 0;
		long hour = 0;
		long min = 0;
		long sec = 0;
		try {
			one = df.parse(str1);
			two = df.parse(str2);
			long time1 = one.getTime();
			long time2 = two.getTime();
			long diff ;
			if(time1<time2) {
				diff = time2 - time1;
			} else {
				diff = time1 - time2;
			}
			day = diff / (24 * 60 * 60 * 1000);
			hour = (diff / (60 * 60 * 1000) - day * 24);
			min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
			sec = (diff/1000-day*24*60*60-hour*60*60-min*60);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return day + "天" + hour + "小时" + min + "分" + sec + "秒";
	}


	/**
	 *
	 * @param monthcount
	 * @return
	 */
	public static String getAfterMonthDate(int monthcount){
		Calendar cal = Calendar.getInstance();
		int year =cal.get(Calendar.YEAR)+1;
		int month=cal.get(Calendar.MONTH)+1;
		cal.add(Calendar.MONTH, monthcount);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		Date date=cal.getTime();
		return sdf.format(date);
	}

    /**
     * 得到n天之后是周几
     * @param days
     * @return
     */
    public static String getAfterDayWeek(String days) {
    	int daysInt = Integer.parseInt(days);
        Calendar calendar = Calendar.getInstance(); // java.util包
        calendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
        Date date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("E");
        String dateStr = sdf.format(date);
        return dateStr;
    }

    public static Map<String,Object> getTodayTime(){
		Map<String,Object> map = new HashMap<>();

		long current=System.currentTimeMillis();//当前时间毫秒数
		long zero=current/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数
		long twelve=zero+24*60*60*1000-1;//今天23点59分59秒的毫秒数
		long yesterday=System.currentTimeMillis()-24*60*60*1000;//昨天的这一时间的毫秒数
		System.out.println(new Timestamp(current));//当前时间
		System.out.println(new Timestamp(yesterday));//昨天这一时间点

		System.out.println(new Timestamp(zero));//今天零点零分零秒
		System.out.println(new Timestamp(twelve));//今天23点59分59秒
		map.put("begin_time",new Timestamp(zero));
		map.put("end_time",new Timestamp(twelve));
		return map;
	}

	public static String getWeekName(int week){
    	if (week > 7){
    		week = 1;
		}
    	try {
			String[] weekNames = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
			return weekNames[week-1];
		}catch (Exception e){
    		e.printStackTrace();
		}
    	return "";
	}


    public static void main(String[] args) {
    	List<Integer> list = new ArrayList<>();
//    	list.add(4);
//    	list.add(5);
//    	list.add(7);
    	System.out.println(getAfterDateByDaysExWeek(new Date(), 3,list));
//    	System.out.println(getAfterDayWeek("3"));
//		System.out.println(getTimeByTimspan(1641986140000L));
    }

}
